home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 23 / Amiga Format AFCD23 (Feb 1998, Issue 107).iso / +look_here_1st!+ / reader_requests / alienbreed3d2 / key.s < prev    next >
Text File  |  1997-11-28  |  4KB  |  219 lines

  1. ;;;=======================================================================
  2. ;;; Filename:      keyboard.s
  3. ;;; Author:        Dave Dixon
  4. ;;; Date Started:  Sat 20 Feb 1993
  5. ;;; Revision:      $Revision: 1.6 $
  6. ;;; Comments:
  7. ;;;           Initialize keyboard interrupt. 
  8. ;;;=======================================================================
  9.  
  10.  
  11. _keycode_    equ    1    ; this file contains keycode!
  12.  
  13.         include    "cmacros.i"
  14.         include    "chipmap.i"
  15.         include "lvo.i"
  16.         incdir    include:
  17.         include "hardware/intbits.i"
  18.         include "exec/nodes.i"
  19.         
  20.         XDEF    _keycode
  21.         XDEF    _keypressed
  22.         XDEF    _scan_2_ascii
  23.         XDEF    _shift_scan_2_ascii
  24.         XDEF    _caps_scan_2_ascii
  25.  
  26.         XREF    _atexit
  27.  
  28.         SECTION    "text",code
  29.  
  30. ;
  31. ; checksum calculator
  32. ;
  33.  
  34.     PROC    GetSum
  35.     USES    d4
  36.     moveq    #0,d0
  37.     moveq    #0,d4
  38.  
  39.     subq    #1,d1            ; for dbra
  40. .chunk
  41.     add.b    (a0)+,d0        ; chk1(d3) += byte 
  42.     add.b    d0,d4            ; chk2(d4) += chk1
  43.  
  44.     subq.l    #1,d1
  45.     bcc.b    .chunk
  46.  
  47.     lsl.w    #8,d4
  48.     or.w    d4,d0            ; return in AX(d3)
  49.     ret
  50.  
  51.  
  52.  
  53.  
  54. ;-------------------------------------------------------------------------
  55. ; Initialize our keyboard interrupt
  56. ;-------------------------------------------------------------------------
  57.  
  58.         PROC    InitKeybd
  59.         USES    a2-a6/d2-d7
  60.  
  61.         cmp.b    #1,KFlag        ; Is our keyboard routine already installed ?
  62.         beq.s    .already_installed
  63.     
  64.         move.l    4.w,a6
  65.         lea    KEYInt(pc),a1
  66.         moveq    #0,d0
  67.         move.b    #INTB_PORTS,d0
  68.         jsr    _LVOAddIntServer(a6)
  69.  
  70.         move.b    #0,_keycode        ; Blank keycode
  71.         pea    _RestoreKeybd        ; atexit(RestoreKeybd)
  72.         jsr    _atexit
  73.         lea.l    4(sp),sp        ; Take parameters off the stack
  74.         move.b    #1,KFlag
  75. .already_installed
  76.         ret
  77.  
  78.  
  79.  
  80. ;-------------------------------------------------------------------------
  81. ; Restore the system interrupt handler 
  82. ;-------------------------------------------------------------------------
  83.  
  84.         PROC    RestoreKeybd
  85.         USES    d2-d7/a2-a6
  86.  
  87.         cmp.b    #1,KFlag
  88.         bne.s    .not_installed
  89.  
  90. ;;; Make sure none of the keys are still pressed when we restore the keyboard vector
  91.  
  92.  
  93. .loop        moveq    #0,d0
  94.         lea.l    _keypressed(pc),a0
  95.         move.w    #128-1,d7
  96. .check_key_loop
  97.         cmp.b    #0,(a0)+
  98.         beq.s    .key_not_pressed
  99.         add.b    #1,d0
  100. .key_not_pressed
  101.         dbra    d7,.check_key_loop
  102.         tst.b    d0
  103.         bne.b    .loop
  104.  
  105. ;;; Now that none of them are pressed we can restore the vector
  106.  
  107.         move.l    4.w,a6
  108.         lea    KEYInt(pc),a1
  109.         moveq    #INTB_PORTS,d0
  110.         jsr    _LVORemIntServer(a6)
  111.  
  112.         move.b    #0,KFlag
  113. .not_installed
  114.         ret
  115.  
  116. ;-------------------------------------------------------------------------
  117. ; Keyboard interrupt 
  118. ;-------------------------------------------------------------------------
  119.  
  120.  
  121. key_interrupt:
  122.         movem.l    d0-d7/a0-a6,-(sp)
  123.  
  124. ;        move.w    INTREQR,d0
  125. ;        btst    #3,d0
  126. ;        beq    .not_key
  127.  
  128.         move.b    $bfdd00,d0
  129.         btst    #0,d0
  130.         bne    .key_cont
  131. ;        move.b    $bfed01,d0
  132. ;        btst    #0,d0
  133. ;        bne    .key_cont
  134.     
  135. ;        btst    #3,d0
  136. ;        beq    .key_cont
  137.  
  138.         move.b    $bfec01,d0
  139.         clr.b    $bfec01
  140.  
  141.         tst.b    d0
  142.         beq    .key_cont
  143.  
  144. ;        bset    #6,$bfee01
  145. ;        move.b    #$f0,$bfe401
  146. ;        move.b    #$00,$bfe501
  147. ;        bset    #0,$bfee01
  148.  
  149.  
  150.         not.b    d0
  151.         ror.b    #1,d0
  152.         lea.l    _keypressed(pc),a0
  153.         tst.b    d0
  154.         bmi.b    .key_up
  155.         and.w    #$7f,d0
  156.         add.w    #1,d0
  157.         move.b    #$ff,(a0,d0.w)
  158.         move.b    d0,_keycode
  159.  
  160.         bra.b    .key_cont2
  161. .key_up:
  162.         and.w    #$7f,d0
  163.         add.w    #1,d0
  164.         move.b    #$00,(a0,d0.w)
  165.  
  166. .key_cont2
  167. ;        btst    #0,$bfed01
  168. ;        beq    .key_cont2
  169. ;        move.b    #%00000000,$bfee01
  170. ;        move.b    #%10001000,$bfed01
  171.  
  172. ;alt keys should not be independent so overlay ralt on lalt
  173.  
  174.         
  175. .key_cont
  176.  
  177. ;        move.w    #$0008,INTREQ
  178. .not_key:    ;lea.l    $dff000,a5
  179.  
  180. ;        lea.l    _keypressed(pc),a0
  181. ;        move.b    101(a0),d0    ;read LALT
  182. ;        or.b    102(a0),d0    ;blend it with RALT
  183. ;        move.b    d0,127(a0)    ;save in combined position
  184.  
  185.         movem.l    (sp)+,d0-d7/a0-a6
  186.  
  187.         rts
  188.  
  189. KFlag
  190.     dc.b    0,0
  191.  
  192.     cnop    0,4
  193. KEYInt
  194.     dc.l    0,0
  195.     dc.b    NT_INTERRUPT,127        ; type,priority
  196.     dc.l    KEYIntName
  197.     dc.l    0
  198.     dc.l    key_interrupt
  199.  
  200. KEYIntName
  201.     dc.b    'KeyInt',0
  202.     even
  203.  
  204.     xdef    _keyptr
  205. _keyptr
  206.     dc.l    _keycode
  207.  
  208. _keypressed    DS.B    128
  209. _keycode    DC.B    $ff
  210. old_keyboard    DS.L    1
  211.  
  212. _scan_2_ascii
  213.     DC.B    " `1234567890-=\ 0qwertyuiop[] 123asdfghjkl;#  456 zxcvbnm,./ .789 "
  214. _shift_scan_2_ascii
  215.     DC.B    " ~! £$%^&*()_+| 0QWERTYUIOP{} 123ASDFGHJKL:@  456 ZXCVBNM<>? .789 "
  216. _caps_scan_2_ascii
  217.     DC.B    " `1234567890-=\ 0QWERTYUIOP[] 123ASDFGHJKL;#  456 ZXCVBNM,./ .789 "
  218.  
  219.         END